package com.study.multithreading.dateformat;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author HBZ
 * @description
 * @date 2021/5/13 14:12
 */
public class DateUtil3ThreadLocal1 {

    private static ThreadLocal<DateFormat> threadLocal = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));

    public static String formatDate(Date date) throws ParseException {
        return threadLocal.get().format(date);
    }

    public synchronized static Date parse(String strDate) throws ParseException {
        return threadLocal.get().parse(strDate);
    }
}
